package com.gulimall.ware.controller;

import java.util.Arrays;
import java.util.Map;

import com.gulimall.ware.vo.PurchaseMergeVo;
import com.gulimall.ware.service.impl.PurchaseServiceImpl;
import com.gulimall.ware.vo.PurchaseVo;
import org.springframework.web.bind.annotation.*;

import com.gulimall.ware.entity.PurchaseEntity;
import com.common.utils.PageUtils;
import com.common.utils.R;

import javax.annotation.Resource;


/**
 * 采购信息
 *
 * @author Rookie-886
 * @email ${email}
 * @date 2021-03-14 22:37:36
 */
@RestController
@RequestMapping("ware/purchase")
public class PurchaseController {
    @Resource
    private PurchaseServiceImpl purchaseServiceImpl;

    /**
     * 列表
     */
    @RequestMapping("/list")
//    @RequiresPermissions("ware:purchase:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = purchaseServiceImpl.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
//    @RequiresPermissions("ware:purchase:info")
    public R info(@PathVariable("id") Long id){
		PurchaseEntity purchase = purchaseServiceImpl.getById(id);

        return R.ok().put("purchase", purchase);
    }
    /**
     * 未领取的采购单（可以是新建、已分配的状态）
     */
    @RequestMapping("/unreceive/list")
    public R getUnReceive(@RequestParam Map<String, Object> params){
        PageUtils page = purchaseServiceImpl.getUnReceiveList(params);

        return R.ok().put("page", page);
    }

    /**
     * 合并采购需求到采购单
     */
    @PostMapping("/merge")
    public R merge(@RequestBody PurchaseMergeVo purchaseMergeVo){
        purchaseServiceImpl.merge(purchaseMergeVo);
        return R.ok();
    }

    /**
     * 领取采购单
     */
    @PostMapping("/received")
    public R received(@RequestBody Long[] purchaseIdArray){
        purchaseServiceImpl.received(purchaseIdArray);
        return R.ok();
    }

    /**
     * 完成采购
     */
    @PostMapping("/done")
    public R done(@RequestBody PurchaseVo purchaseVo){
        purchaseServiceImpl.done(purchaseVo);
        return R.ok();
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
//    @RequiresPermissions("ware:purchase:save")
    public R save(@RequestBody PurchaseEntity purchase){
        purchaseServiceImpl.save(purchase);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
//    @RequiresPermissions("ware:purchase:update")
    public R update(@RequestBody PurchaseEntity purchase){
        purchaseServiceImpl.updateById(purchase);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
//    @RequiresPermissions("ware:purchase:delete")
    public R delete(@RequestBody Long[] ids){
        purchaseServiceImpl.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
